package com.dglg.spring.controller;

import com.dglg.spring.model.User;
import com.dglg.spring.service.LoginService;
import org.apache.xmlbeans.impl.xb.xsdschema.Attribute;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class LoginController {

    @Autowired
    private LoginService loginService;

    @RequestMapping(value = "/userLogin/submit", method = RequestMethod.POST)
    public Result userLogin(HttpServletRequest request) {


        User user = loginService.getUser(request.getParameter("account"), request.getParameter("password"));
        System.out.println(user);

        Integer code = user != null ? Code.GET_OK : Code.GET_ERR;
        String msg = user != null ? "登录成功！" : "登录失败，请重试！";

        return new Result(code, user, msg);
    }

}
